Skip to content

ci(security): read alert recipients and chat IDs from secrets - #556

Merged
Pigbibi merged 6 commits into
mainfrom
ci/firstrade-alert-secrets-migration
Nov 27, 2026
Merged

Pigbibi merged 6 commits into
mainfrom
ci/firstrade-alert-secrets-migration

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

AI assistance

Antigravity AI assistant (gemini-3.1-pro)

What changed

  • Switch STRATEGY_PLUGIN_ALERT_EMAIL_RECIPIENTS, STRATEGY_PLUGIN_ALERT_EMAIL_SENDER_EMAIL, and STRATEGY_PLUGIN_ALERT_TELEGRAM_CHAT_IDS in .github/workflows/sync-cloud-run-env.yml from ${{ vars.* }} to ${{ secrets.* }}.
  • Update tests/test_sync_cloud_run_env_workflow.py to assert those 3 variables are read from secrets.* and absent from vars.*.

How verified

  • git diff --check passed.
  • Verified no vars.STRATEGY_PLUGIN_ALERT_(EMAIL_RECIPIENTS|EMAIL_SENDER_EMAIL|TELEGRAM_CHAT_IDS) references remain in the repository.
  • uv run --with pytest pytest -q tests/test_sync_cloud_run_env_workflow.py tests/test_paper_notification_preview.py -> 30 passed in 38.47s.

Why

The matching repository secrets (STRATEGY_PLUGIN_ALERT_EMAIL_RECIPIENTS, STRATEGY_PLUGIN_ALERT_EMAIL_SENDER_EMAIL, STRATEGY_PLUGIN_ALERT_TELEGRAM_CHAT_IDS) are now staged in FirstradePlatform. Switching the workflow to secrets.* prevents alert recipient/chat identifiers from remaining exposed as public repository variables and unblocks deleting those 3 public vars.* after merge.

Risk

  • Tier: sensitive path (.github/workflows/).
  • Impact: CI/workflow wiring only; no Cloud Run deployment or runtime behavior changes (matching secrets are already staged). Zero email addresses or Telegram chat IDs committed.

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The change moves three alert-identifier variables from vars.* to secrets.* in the sync workflow and updates the test accordingly. The diff is small and consistent. However, the workflow appears to use these values in a job-level env: block that feeds a sync-plan script; if that script or any downstream step echoes the environment (e.g., env, set -x, or logging the plan), the newly-secret values could be masked but still leak into logs, and the test only checks textual presence, not that the values are not printed. More importantly, the test asserts absence of vars.<name> but does not verify the workflow still fails closed when the secrets are unset (empty string), which could silently disable alerting. No hardcoded secrets, no permission changes, and no third-party action changes are present.

Reviewed commit: 9298215feb · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] .github/workflows/sync-cloud-run-env.yml: Switching to secrets.* means the values are masked in logs, but if the sync-plan script or any step prints the resolved env/plan (e.g., env, set -x, or dumping the plan JSON), the recipient/chat IDs can still leak. Verify the consuming script does not echo these variables and that the plan output is redacted.
  • [MEDIUM] tests/test_sync_cloud_run_env_workflow.py: The test only asserts textual presence of secrets.<name> and absence of vars.<name>. It does not cover the fail-closed behavior when the secrets are unset (empty string), which could silently disable email/Telegram alerting. Add a test asserting the workflow/script rejects or warns on empty alert identifiers.
  • [LOW] .github/workflows/sync-cloud-run-env.yml: The PR description says the matching secrets are 'staged' but not yet confirmed present. If the secrets are not actually configured, the workflow will now pass empty strings where it previously passed public vars, changing runtime alerting behavior. Confirm the secrets exist before merge.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T18:20:10.113753Z 0b0aae7 Manual request
🔒 Security Review ✅ Completed 2026-11-27T18:21:35.559088Z 0b0aae7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The change moves three alert identifiers from vars.* to secrets.* and adds a fail-closed guard. The intent is sound, but the new guard has a correctness bug: the channel-normalization expression tr '; ' ',,' is wrong (tr maps char-by-char, so ';'->',' and ' '->',' is fine actually, but the surrounding comma wrapping plus substring match *",email,"* only works if channels are comma-separated; semicolons and spaces are converted, so that part is okay). The real issue is that the guard is placed in the workflow but the test re-implements the missing_vars loop rather than exercising the real workflow logic, so the test can pass while the workflow diverges. Also the guard only checks emptiness of the secret-derived env, but GitHub Actions secrets that are unset resolve to empty string, which is handled. However, the required_vars+=(STRATEGY_PLUGIN_ALERT_EMAIL_RECIPIENTS) path relies on indirect expansion ${!var_name:-} in the real workflow — need to confirm the real loop uses indirect expansion; the test hardcodes it, so if the workflow uses a different check the test is not faithful. Additionally, the new test asserts "set -x" not in workflow and echo checks which are unrelated to this PR and add noise. No hardcoded secrets leaked.

Reviewed commit: d2af4ba4a1 · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] tests/test_sync_cloud_run_env_workflow.py: The new fail-closed test reconstructs the missing_vars loop and footer by string-splitting the workflow and re-implementing the indirect-expansion check inline. It does not execute the workflow's actual validation logic, so a divergence between the real loop (e.g. different emptiness check or ordering) and the test's copy would go undetected. Extract the validation into a sourced script or run the real step to make the test faithful.
  • [MEDIUM] .github/workflows/sync-cloud-run-env.yml: The fail-closed guard depends on the downstream loop using indirect expansion ${!var_name:-} to detect empty secret-derived values. If the existing loop only checks -z "${!var_name}" without :-, set -u will abort on unset vars before producing the intended missing-vars message, and the ' or ' pseudo-variable handling must also be verified. Confirm the real loop matches the test's reimplementation.
  • [LOW] tests/test_sync_cloud_run_env_workflow.py: Assertions assert "set -x" not in workflow and the two echo "${SYNC_PLAN_JSON}" checks are unrelated to this PR's scope and add maintenance noise; they belong in a dedicated secret-leak test if kept.
  • [LOW] .github/workflows/sync-cloud-run-env.yml: tr '; ' ',,' maps each char individually which is correct, but the normalization does not trim leading/trailing whitespace or handle tabs/newlines in STRATEGY_PLUGIN_ALERT_CHANNELS, so a value like email\n or email would not match ,email, and the guard would silently not fire. Consider normalizing all whitespace.

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The change moves three alert identifiers from vars.* to secrets.* and adds a fail-closed validation step plus tests. The core wiring is correct and the new test exercises the validation script. However, the new validation logic has a subtle correctness issue: the channel normalization uses tr '[:upper:];[:space:]' '[:lower:],,' which maps each character class to a single replacement char, so multi-char separators and the ;/whitespace handling may not behave as intended, and the substring match *",email,"* can miss channels when the normalized string has different delimiters. Also, the fail-closed check only validates presence, not that secrets are non-empty at deploy time (GitHub secrets resolve to empty string when unset, which is handled), but the GLOBAL_TELEGRAM_CHAT_ID fallback means a telegram channel with only the global chat id passes while STRATEGY_PLUGIN_ALERT_TELEGRAM_CHAT_IDS stays empty — acceptable but worth noting. No credential leakage, permissions unchanged, actions not touched. Main concern is the fragile normalization logic and lack of a test asserting the ;-separated and mixed-case normalization edge cases beyond the single happy-path string.

Reviewed commit: d2ae0e311e · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] .github/workflows/sync-cloud-run-env.yml: Channel normalization tr '[:upper:];[:space:]' '[:lower:],,' maps the entire [:space:] class and ; to a single , each, but tr set-to-set mapping with unequal lengths repeats the last char of set2, so this works only by accident. More importantly, the substring checks *",email,"* / *",telegram,"* require the channel token to be exactly delimited by commas; a value like email,telegram normalizes to ,email,telegram, and matches, but a value with a trailing/leading token or an unknown separator (e.g. | or +) silently fails to trigger the fail-closed guard, letting an enabled channel deploy with empty recipients. Consider splitting on a defined separator set and matching tokens exactly, and add a test for a non-comma separator to prove the guard fails closed.
  • [LOW] tests/test_sync_cloud_run_env_workflow.py: The new test only covers the happy path and the two missing-secret cases with comma/space/semicolon input. It does not assert behavior for mixed separators, duplicate channels, or the case where STRATEGY_PLUGIN_ALERT_CHANNELS contains telegram but only GLOBAL_TELEGRAM_CHAT_ID is set (the intended fallback). Adding those cases would lock in the fail-closed contract and catch regressions in the normalization logic.
  • [LOW] .github/workflows/sync-cloud-run-env.yml: The fail-closed check validates presence of the secret-derived env vars but does not distinguish an unset secret (empty string) from a deliberately empty value; both are treated as missing, which is correct for fail-closed, but the error message STRATEGY_PLUGIN_ALERT_TELEGRAM_CHAT_IDS or GLOBAL_TELEGRAM_CHAT_ID is a synthetic pseudo-variable name that the downstream missing_vars loop must special-case. Confirm that loop handles the " or " sentinel correctly (the diff shows a *" or "* branch) and that it does not attempt to look up a real env var by that literal name.

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The change moves three alert identifiers from vars.* to secrets.* and adds a fail-closed validation step. The workflow wiring and tests look consistent, but the new validation logic has a correctness gap: it only checks the STRATEGY_PLUGIN_ALERT_CHANNELS variable, while the actual runtime may enable channels via other paths, and the GLOBAL_TELEGRAM_CHAT_ID fallback is accepted without verifying TELEGRAM_TOKEN, which could let a misconfigured deploy pass validation. Also, the validation runs before the sync plan is parsed, so it may fail even when no target actually needs alert channels.

Reviewed commit: 58b52c9f0b · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] .github/workflows/sync-cloud-run-env.yml: The new fail-closed check accepts GLOBAL_TELEGRAM_CHAT_ID as a fallback for STRATEGY_PLUGIN_ALERT_TELEGRAM_CHAT_IDS but does not verify that the corresponding TELEGRAM_TOKEN (or bot token secret) is present. A deploy with only GLOBAL_TELEGRAM_CHAT_ID set and no token would pass validation and then fail at runtime when sending alerts, defeating the fail-closed intent. Either require the token alongside the fallback or drop the fallback.
  • [MEDIUM] .github/workflows/sync-cloud-run-env.yml: The validation runs unconditionally before SYNC_PLAN_JSON is parsed and before targets are inspected. If the sync plan has no targets (or targets that do not enable alert channels), the step still fails when STRATEGY_PLUGIN_ALERT_CHANNELS is set but secrets are empty. This couples validation to a global env var rather than the actual per-target configuration and can block unrelated syncs. Consider gating the check on whether any target actually enables the channel.
  • [LOW] tests/test_sync_cloud_run_env_workflow.py: The new test extracts the step script by string-splitting on ' - name: Validate env sync inputs\n' and '\n - name: Wait for Cloud Run deployment of current commit'. This is brittle to whitespace/step-name changes and will raise IndexError rather than a clear assertion if the step is renamed. Consider asserting the split succeeded with a descriptive message.
  • [LOW] tests/test_sync_cloud_run_env_workflow.py: The test asserts the three variables are absent from vars.* via substring check, but does not assert they are absent from any other workflow file or that the secrets are actually referenced in the env block passed to the sync step (only that the string appears somewhere in the workflow). A stronger assertion would scope the check to the env: block of the sync step.

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The PR switches three alert identifiers from vars.* to secrets.* and adds a fail-closed validation step plus tests. The core change is sound and the new validation is well covered. However, the new validation logic has a subtle correctness issue: it reads STRATEGY_PLUGIN_ALERT_CHANNELS only from target_env, while the test asserts per-target gating (test case 1 passes when global env has email enabled but target has no channels). This is intentional per the test, but it means the validation can be bypassed if the sync plan omits the channels key while the deployed service actually has channels configured via other means — a fail-open gap. Additionally, the validation checks STRATEGY_PLUGIN_ALERT_TELEGRAM_BOT_TOKEN_SECRET_NAME/TELEGRAM_TOKEN_SECRET_NAME (secret names) as if they were the token itself, which conflates a reference with a value and could pass validation while the actual secret is empty.

Reviewed commit: d8fc8b196b · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] .github/workflows/sync-cloud-run-env.yml: The new fail-closed check derives channels only from target_env.get("STRATEGY_PLUGIN_ALERT_CHANNELS"). If the sync plan's target env omits STRATEGY_PLUGIN_ALERT_CHANNELS (e.g. it is inherited from the existing Cloud Run revision or set elsewhere), the check silently skips all alert-secret validation and passes — a fail-open gap for exactly the secrets this PR is trying to protect. Consider falling back to os.environ.get("STRATEGY_PLUGIN_ALERT_CHANNELS") (as _resolved_value already does for other keys) or failing closed when channels are unknown but alert secrets are expected.
  • [MEDIUM] .github/workflows/sync-cloud-run-env.yml: The telegram token check treats STRATEGY_PLUGIN_ALERT_TELEGRAM_BOT_TOKEN_SECRET_NAME and TELEGRAM_TOKEN_SECRET_NAME (secret names, i.e. references) as satisfying the requirement for an actual bot token. A configured secret name does not prove the referenced secret has a value, so validation can pass while the deployed service has no usable token. Either validate the referenced secret's presence separately or restrict the check to actual token values (STRATEGY_PLUGIN_ALERT_TELEGRAM_BOT_TOKEN / TELEGRAM_TOKEN).
  • [LOW] tests/test_sync_cloud_run_env_workflow.py: Test case 1 asserts that a target with no alert channels passes even when the global env has STRATEGY_PLUGIN_ALERT_CHANNELS=email. This codifies the fail-open behavior described above as intended; if the workflow is fixed to fall back to the global env, this test will need updating. Worth a comment explaining why per-target gating is the desired semantics.
  • [LOW] tests/test_sync_cloud_run_env_workflow.py: The new test extracts the validation script by string-splitting on " - name: Validate env sync inputs\n" and "\n - name: Wait for Cloud Run deployment of current commit". This is brittle to step renames/reordering and to indentation changes; a small YAML parse (or a shared helper) would be more robust and is already used elsewhere in the file for other steps.

@Pigbibi

Pigbibi commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@qsl-ai-reviewer

Copy link
Copy Markdown

AI Code Review (deepseek / deepseek-chat)

The change moves three alert-identifier variables from vars.* to secrets.* in the deploy job env and updates the test accordingly. The workflow edit itself is correct and consistent with the stated intent. However, the new test has a structural weakness: it splits the workflow on the literal ' deploy-cloud-run:\n' and '\n steps:\n' to isolate the job env block, which is brittle and could silently pass or fail if indentation/step layout changes; more importantly, the cross-workflow assertion only checks for the literal substring 'vars.', so it would not catch other exposure forms (e.g., env: blocks referencing the same identifiers via different syntax, or the values being echoed). No high/medium correctness or security bug is introduced by the diff itself.

Reviewed commit: 0b0aae724e · Coverage: complete · Unresolved findings: false

Findings

  • [LOW] tests/test_sync_cloud_run_env_workflow.py: The new test isolates the deploy job env by splitting on the literal strings ' deploy-cloud-run:\n' and '\n steps:\n'. This is brittle: any change to job name, indentation, or step layout (e.g., adding a job-level key before steps, or a differently-indented 'steps:') will make the split return the wrong slice and the assertions may pass vacuously or fail spuriously. Prefer parsing the YAML (yaml.safe_load) and asserting on the parsed job env mapping.
  • [LOW] tests/test_sync_cloud_run_env_workflow.py: The cross-workflow guard only asserts the literal substring 'vars.' is absent. It would not catch the identifiers being exposed via other forms (e.g., 'vars[NAME]', env indirection, or values echoed into logs). Consider asserting the identifiers appear only under secrets.* in the deploy env and are not present in any 'vars.' context more robustly.
  • [LOW] .github/workflows/sync-cloud-run-env.yml: Switching to secrets.* means these values are masked in logs, but the workflow should ensure they are not echoed (e.g., via 'set -x' or debug output) when passed to the sync-plan script. Confirm the downstream script does not print the env values; the diff does not show that boundary.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 0b0aae724e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Pigbibi Pigbibi added the agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation label Nov 27, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0b0aae724e

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@Pigbibi
Pigbibi merged commit 9672398 into main Nov 27, 2026
13 of 14 checks passed
@Pigbibi
Pigbibi deleted the ci/firstrade-alert-secrets-migration branch November 27, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant